﻿@model MvcCoffeeShop.DataTransferObjects.ProductDTO
@{
    ViewBag.Title = "PendingCartItem";
}


<script type="text/javascript">

    function addToCart() {
        //Use JQuery/AJax to reduce postbacks to the server.
        var frmProductID = $("#hdnProductID").val();
        var frmQuantity = $("#ddlMaximumOrders").val();

        //alert(frmProductID);
        //alert(frmQuantity);
        
        var postToControllerActionResult = '@Url.Action("PendingCartItem")';

        $.ajax({
            type: "POST",
            url: postToControllerActionResult,
            data: { productid: frmProductID, quantity: frmQuantity },
            success: function (json) {
                if (json.result) {
                    var url = '@Url.Action("Index", "ShoppingCart")';
                    window.location.href = url;
                }
                else {
                    window.alert(' error : ' + returndata.message);
                }
            }
            }
        );


    }
</script>

<h2>Product Description</h2>
 
 @using (Html.BeginForm())
 {
            <table style="border-width:1px;border-style:solid;">
     
   
           <tr>
                <td>
                    <img src="/Images/MvcCoffeeShop/@Url.Content(Model.PicturePath)" />
                </td>
                <td>
                    <h2>@Model.ProductName</h2>
                    <h3>@Model.ProductDesc</h3>
                    <h3>Unit Price: @Model.UnitPrice</h3>   
                    <h3>Quantity:  @Html.DropDownList("ddlMaximumOrders", ViewBag.MaximumQuantity as IEnumerable<SelectListItem>)</h3>
                    <br />
             
                    <button type="button" onclick="addToCart();">Add To Cart</button>
                     &nbsp;&nbsp;
                     @Html.ActionLink("Cancel", "Catalog", "Home")
                   </td>
                             
              </tr>
        
              </table>
     
     
                @Html.Hidden("hdnProductID", (int)ViewBag.ProductID)
        
    }

   
